package edu.udel.mboch.towerdefense;

import java.io.Serializable;

public class Position implements Serializable
{
	private static final long serialVersionUID = -1911771754565869687L;
	protected int x;
	protected int y;
	
	public Position(int x, int y)
	{
		this.x = x;
		this.y = y;
	}
	
	public int x()
	{
		return x;
	}
	
	public void x(int x)
	{
		this.x = x;
	}
	
	public int y()
	{
		return y;
	}
	
	public void y(int y)
	{
		this.y = y;
	}
	
	public float[] vectorTowards(Position p)
	{
		float[] vector = new float[2];
		if(p.x() > x)
			vector[0] = 1f;
		else if(p.x() < x)
			vector[0] = -1f;
		else
			vector[0] = 0f;
		if(p.y() > y)
			vector[1] = 1f;
		else if(p.y() < y)
			vector[1] = -1f;
		else
			vector[1] = 0f;
		return vector;
	}
	
	public Position copy()
	{
		return new Position(x,y);
	}
	
	public boolean equals(Object other)
	{
		Position pos = (Position)other;
		return pos.x() == x && pos.y() == y;
	}
	
	public String toString()
	{
		return x + " " + y;
	}
}
